import org.springframework.security.context.SecurityContextHolder as SCH

abstract class Timeline implements Comparable<Timeline> {
    Date fromDate = new Date() 
    Date toDate
    //the user defaults to the currently logged in user
    User user =  SCH.context?.authentication?.principal != null ? User.findByUsername(SCH.context?.authentication?.principal.username) : null 

    static constraints = {
        fromDate(nullable: false)
        toDate(nullable: true)
        user(blank: false)
    }

    static mapping = {
        tablePerHierarchy: false
    }

    public int compareTo(Timeline timeline) {
        return fromDate.compareTo(timeline.getFromDate())
    }
}
